1. Field of the Invention
The present invention relates to technology for encoding image data.
2. Description of the Related Art
In order to efficiently handle digital images, image compression to reduce the file size thereof is indispensable. Examples of documents that disclose such technology include Japanese Patent Laid-Open No. 2009-505494 (hereinafter, Document 1), “Recent trend in standardization of JPEG XR” Institute of Image Electronics Engineers of Japan, Vol. 37, No. 4: pp. 502-512, Jul. 25, 2008 (hereinafter, Document 2), and Nikkei Electronics Dec. 29, 2008: pp. 71-77, Dec. 29, 2008 (hereinafter, Document 3).
With technology on the basis of the above technology, a macro block (MB) having a 16×16 pixel size is defined, frequency conversion is performed, and thereafter quantization and entropy encoding are performed. In entropy encoding, high frequency coefficients that are encoding targets are regarded as values of natural binary representation, and separated into upper bits and lower bits as shown in FIG. 6. The upper bits are referred to as HPu (HP upper), and the lower bits are referred to as FLEXBITS. With these two types of data, HPu have many “0” bits and can be easily compressed, and thus Huffman encoding is implemented thereon. On the other hand, FLEXBITS have substantially randomly “0” and “1” bits and cannot be easily compressed, and thus are output without being compressed. Moreover, taking the effect of compression into consideration, it is desirable to change the bit number of FLEXBITS in an image rather than fixed it. Because, if a region not including many edges is compared with a region including many edges, in the former region, bits close to an LSB (Least Significant Bit) also include many “0” bits. On the other hand, in the latter region, even bits close to an MSB (Most Significant Bit) include “0” and “1” bits that tend to exist randomly. That is, it is better to assign a small bit number of FLEXBITS to the former region so as to increase the number of bits that are to be encoded as HPu. The opposite applies to the case of the latter region. In consideration of this point, with technology based on Document 1 and the like, a mechanism for dynamically changing the bit number of FLEXBITS in the range of ±1 between MBs adjoining in a main scanning direction in units of macro blocks is adopted. Here, the reason for setting a limitation, that is, “the range of ±1”, is that the same number of bits in an entire image can delete lower bits of FLEXBITS. Consequently, this suppresses a state where a great difference in image quality may be generated between adjoining MBs in the case where all FLEXBITS are deleted or the like.
However, there is no restriction placed on the difference in the bit number of FLEXBITS with respect to MBs except between MBs adjoining in the main scanning direction. For example, with JPEG XR, how much difference there is in the bit number of FLEXBITS between two MBs at separate positions in an image or between MBs adjoining in the sub-scanning direction is unknown. Accordingly, a difference in image quality may be generated between MBs depending on the number of bits to be deleted. In particular, if a difference in image quality occurs between MBs adjoining in the sub-scanning direction, this will be perceived as distortion and become a problem.